package sandeep.databases;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;


public class DatabaseHelper extends SQLiteOpenHelper{
	private static final String DATABASE_NAME="lunchlist.db";
	private static final int SCHEMA_VERSION=1;

	public DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, SCHEMA_VERSION);

	}

	@Override
	public void onCreate(SQLiteDatabase db) {

		db.execSQL("CREATE TABLE items (_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT);");
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

		
	}
	
	//to insert into the database
	public void insert(String title) {
			ContentValues cv=new ContentValues();
			cv.put("title", title);
			getWritableDatabase().insert("items", null, cv);
			
			}
	
	//returns all items in the database
	public Cursor getAll() {
		return(getReadableDatabase()
		.rawQuery("SELECT _id, title FROM items ORDER BY title", null));
		}
	public String getTitle(Cursor c)
	{
		return c.getString(1);
				
	}

}
